package protocol

import (
	"context"
	"net/http"
	"time"

	"gitee.com/yangwencheng/vblog/config"
	"github.com/gin-gonic/gin"
)

func NewHttp(r *gin.Engine) *Http {

	s := &http.Server{
		Addr:         config.C().Http.Address(),
		Handler:      r,
		ReadTimeout:  10 * time.Second,
		WriteTimeout: 10 * time.Second,
	}
	return &Http{
		server: s,
	}
}

type Http struct {
	server *http.Server
}

// 启动方法
func (h *Http) Start() error {
	return h.server.ListenAndServe()
}

// 停止方法
func (h *Http) Stop(ctx context.Context) error {
	return h.server.Shutdown(ctx)
}
